package org.example.springboot.service;

import org.example.springboot.entity.Classification;
import org.example.springboot.mapper.ClassificationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ClassificationService {

    @Autowired
    ClassificationMapper classificationMapper;

    public List<Classification> getClassificationsByPage(int pageNum, int pageSize, String course) {
        int offset = (pageNum - 1) * pageSize;
        return classificationMapper.getClassificationsByPage(pageSize,offset, course);
    }

    public int getClassificationCount(String course) {
        return classificationMapper.getClassificationCount(course);
    }

    @Transactional
    public void deleteClassificationByAccount(String course) {
        classificationMapper.deleteClassificationByCourse(course);
    }

    @Transactional
    public void insertClassification(Classification  classification) {
        classificationMapper.insertClassification( classification);
    }

    public  Classification getClassificationByAccount(String course) {
        return classificationMapper.selectByCourse(course);
    }

    @Transactional
    public void updateClassification(Classification user) {
        classificationMapper.updateClassification(user);
    }

    public List<Classification> selectAllClassification() {
        return classificationMapper.selectAll();
    }
}
